﻿using System;
using System.Windows.Data;
using System.Windows.Media;
using CPETwit.WPFClient.Common;

namespace CPETwit.WPFClient.Converter
{
    public class BytesToImageSourceConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if(value is byte[] || value == null)
                return CommonData.GetImageSourceFromAvatar(value as byte[]);
            if (value is ImageSource)
                return value;
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value is ImageSource)
                return CommonData.GetAvatarFromImageSource(value as ImageSource);
            return null;
        }
    }
}
